﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DAO
{
    public class SalesDao
    {
        public SalesDao()
        {
          new SqlHelper();
        }
        public bool insertSales(int productId, int? cusId, decimal price, decimal quantity, 
            decimal payMoney, decimal debitMoney, DateTime saleDate)
        {
            return SqlHelper.ExecuteNonQuery("SP_INSERT_SALES", CommandType.StoredProcedure,
                "@PRO_ID", productId,
                "@CUS_ID", cusId,
                "@PRICE", price,
                "@QUAN", quantity,
                "@PAY", payMoney,
                "@DEBIT", debitMoney,
                "@USR_ID", LoginDao.userID,
                "@SALE_DATE", saleDate);
        }

        
        public DataTable getSales(DateTime fromDate, DateTime toDate)
        {
            return SqlHelper.ExecuteDataTable("SP_GET_SALES", CommandType.StoredProcedure,
                "@FROM_DATE", fromDate,
                "@TO_DATE", toDate);
        }

        public DataTable getSalesReport(DateTime fromDate, DateTime toDate)
        {
            return SqlHelper.ExecuteDataTable("SP_GET_SALES_REPORT", CommandType.StoredProcedure,
                "@FROM_DATE", fromDate,
                "@TO_DATE", toDate);
        }


        public DataTable getDebitCustomer(string customerName, int status, DateTime fromDate, DateTime toDate)
        {
            return SqlHelper.ExecuteDataTable("SP_GET_DEBIT", CommandType.StoredProcedure,
                "@CUSTOMER_NAME", customerName,
                "@STATUS", status,
                "@FROM_DATE", fromDate,
                "@TO_DATE", toDate);
        }

        public DataTable getDebitCustomerById(int id)
        {
            return SqlHelper.ExecuteDataTable("SP_GET_CUSTOMER_DEBIT", CommandType.StoredProcedure,
                "@CUSTOMER_ID", id);
        }
        
        public bool deleteSale(int id)
        {
            return SqlHelper.ExecuteNonQuery("SP_DELETE_SALE", CommandType.StoredProcedure,
                "@ID", id,
                "@USR_ID", LoginDao.userID);
        }

        public bool debitCollect(int id)
        {
            return SqlHelper.ExecuteNonQuery("SP_DEBIT_COLLECTION", CommandType.StoredProcedure,
                "@ID", id,
                "@USR_ID", LoginDao.userID);
        }
    }
}
